package com.mar.framecompress.impl;

import com.mar.framecompress.IColorDecoder;
import com.mar.framecompress.IColorEncoder;

public class EightBitColorDecoderEncoder implements IColorDecoder,
		IColorEncoder {

	public int decode(int comporessedColor, int actualBits) {
		assert actualBits == 8;
		
		int _8bitColor  = comporessedColor;
		
		int red = ((_8bitColor >>0 &7) * 36 ) << 16 ;

	    int  green = (_8bitColor >>3 &7) * 36 << 8 ;

	    int   blue = (_8bitColor >>6 &3) * 85; 
	    
	    return (red | green | blue);
	}

	public int encode(int argb) {
		int b = (argb & 0xC0) >>> ((8 - 2) - 6);
		int g = (argb & 0xE000) >>> ((8 - 3 + 8) - 3);
		int r = (argb & 0xE00000) >>> ((8 - 3 + 8 + 8) - 0);
		byte value = (byte)(r | g | b);
		return value;
	}

	public int getActualBits() {
		return 8;
	}
	

}
